package com.dhcc.core.framework.security.client.oauth2;

import com.dhcc.core.config.properties.SsoProperties;
import com.github.scribejava.core.builder.api.DefaultApi20;
import com.github.scribejava.core.extractors.TokenExtractor;
import com.github.scribejava.core.model.OAuth2AccessToken;

public class DthApi extends DefaultApi20 {

    private String key;

    private String secret;

    public DthApi(String key, String secret) {
        setKey(key);
        setSecret(secret);
    }

    @Override
    public String getAccessTokenEndpoint() {
        StringBuilder finialUrl = new StringBuilder();
        finialUrl.append(SsoProperties.me().getServerUrl());
        finialUrl.append("/accessToken");
        finialUrl.append("?client_id=" + key);
        finialUrl.append("&client_secret=" + secret);

        return finialUrl.toString();
    }

    @Override
    protected String getAuthorizationBaseUrl() {
        return SsoProperties.me().getDynamicServerUrl() + "/authorize";
    }

    @Override
    public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() {
        return DthJsonExtractor.instance();
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }
}


